<template>
  <div class="login-main">
    <div class="login-form">
      <h2>喵喵喵后台管理登录</h2>
      <el-form label-width="60px" class="form">
        <el-form-item label="手机号">
          <el-input v-model="contactNumber" size="large"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="password" type="password" size="large"></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button @click="userLogin(contactNumber, password)">登录</el-button>
          <el-button @click="userSign">注册</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import useStore from '../../stores/user'
import { reactive, toRefs } from 'vue'
import { userLoginApi } from '../../api/users/login'

import menuStore from '../../stores/menu'

import router from '@/router'
const store = useStore()
const menu = menuStore()
const state = reactive({
  contactNumber: '123456789',
  password: '123456'
})
const userLogin = async (contactNumber, password) => {
  try {
    const res = await userLoginApi(contactNumber, password)
    await menu.getMenuList(res.data.role)
    await store.getToken(res.data.token)
  } catch (error) {
    console.log(error)
  }
}
const userSign = () => {
  router.push({ name: 'sign' })
}
const { contactNumber, password } = toRefs(state)
</script>
<style lang="scss" scoped>
.login-main {
  position: relative;
  height: 100%;
  width: 100%;
  background: url(../../assets/img/img1.jpg);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  .login-form {
    position: relative;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 250px;
    background: rgba($color: #e0aad4, $alpha: 0.6);
    border-radius: 10px;
    // display: flex;
    padding: 16px;
    box-sizing: border-box;
    h2 {
      text-align: center;
    }
    .form {
      position: relative;
      top: 30px;
    }
    .login-btn {
      width: 100%;
      text-align: center;
    }
  }
}
</style>
